<template>
  <!-- <el-menu-item index="1">
    <el-icon><Platform /></el-icon>
    <span>控制台</span>
  </el-menu-item>
  <el-sub-menu index="2">
    <template #title>
      <el-icon><Setting/></el-icon>
      <span>权限管理</span>
    </template>
    <el-menu-item-group>
      <el-menu-item index="2-1">帐号管理</el-menu-item>
      <el-menu-item index="2-2">菜单管理</el-menu-item>
    </el-menu-item-group>
  </el-sub-menu>
  <el-sub-menu index="3">
    <template #title>
      <el-icon><BellFilled /></el-icon>
      <span>小黄人陪诊</span>
    </template>
    <el-menu-item-group>
      <el-menu-item index="3-1">陪护管理</el-menu-item>
      <el-menu-item index="3-2">订单管理</el-menu-item>
    </el-menu-item-group>
  </el-sub-menu> -->
  <template v-for="(item, index) in props.menuData">
    <el-menu-item
        @click="handleClick(item, `${props.index}-${item.meta.id}`)"
        v-if="!item.children || item.children.length == 0"
        :index="`${props.index}-${item.meta.id}`"
        :key="`${props.index}-${item.meta.id}`"
    >
     <el-icon size="20">
        <component :is="item.meta.icon"></component>
      </el-icon>
        <span>{{ item.meta.name }}</span>
    </el-menu-item>
    <el-sub-menu v-else :index="`${props.index}-${item.meta.id}`">
        <template #title>
            <el-icon size="20">
                <component :is="item.meta.icon"></component>
            </el-icon>
            <span>{{ item.meta.name }}</span>
        </template>
        <tree-menu :index="`${props.index}-${item.meta.id}`" :menu-data="item.children"/>
    </el-sub-menu>
  </template>

</template>
<script setup>
import { useRouter } from "vue-router";
import { useStore } from 'Vuex';

const store = useStore()
// 获取路由实例
const router = useRouter()

const props = defineProps(['menuData', 'index'])
console.log(props, 'props')
// 点击菜单
const handleClick = (item, active) => {
  store.commit('addMenu', item.meta)
  store.commit('updateMenuActive', active )
  router.push(item.meta.path)
}
</script>
<style lang="scss" scoped>

</style>
